#coding:utf8

import redis

# 创建连接
#
config = {'host': 'localhost', 'port': 6379, 'db': 0}


#set, get 一个字符串
def set():
    r = redis.Redis(**config)
    r.set('name', 'zhangsan')
    print(r.get('name'))


def pool_set():
    pool = redis.ConnectionPool(**config)
    r = redis.Redis(connection_pool=pool)
    r.set('name1', 'francis')  #添加
    print(r.get('name1'))  #获取


#带有效期的set
def set_with_expire_time():
    r = redis.Redis(**config)
    r.set('name', 'francis with expire time', 5)
    print(r.get('name'))


#获取一个key的值
def get(key):
    r = redis.Redis(**config)
    print(r.get(key))


if __name__ == '__main__':
    get('name')
